<?php

class Topic
{
	private $Database;
	
	public function __construct(Database $db)
	{
		$this->Database = $db;
	}
	
	/**
	 * Get posts in this topic
	 * @param int $topicID
	 */
	public function getPosts($topicID, $start = 0)
	{
		$sql = 'SELECT *
				FROM ' . CBB_POSTS . "
				WHERE topic_id = $topicID
				LIMIT $start,$configPostsLimit";
		
		$result = $this->Database->execute($sql);
		
		return $this->Database->fetchassoc($result);
	}
	
	public function addTopic()
	{
		
	}
	
	public function editTopic($topicID /* ... */)
	{
		
	}
	
	public function removeTopic($topicID)
	{
		// First remove all posts in this topic...
		$sql = 'REMOVE FROM ' . CBB_POSTS . "
				WHERE topic_id = $topicID";
		
		$this->Database->execute($sql);
		
		// ... then delete the topic itself
		$sql = 'REMOVE FROM ' . CBB_TOPICS . "
				WHERE topic_id = $topicID";
		
		$this->Database->execute($sql);
	}
}

?>